package com.sqisland.dash;

import java.util.HashSet;

import android.content.Context;

public class TextSensorManager extends BluetoothSensorManager {
  public static final String TYPE = "text";

  private HashSet<Listener> listeners = new HashSet<Listener>();

  public TextSensorManager(Context context, String address, String name) {
    super(context, address, name);
  }

  @Override
  public void handleIncomingMessage(byte[] buffer, int length) {
    String msg = new String(buffer, 0, length);
    for (Listener listener : listeners) {
      if (listener != null) {
        listener.onMessageReceived(msg);
      }
    }
  }

  public void addListener(Listener listener) {
    listeners.add(listener);
  }

  public void removeListener(Listener listener) {
    listeners.remove(listener);
  }

  public interface Listener {
    public void onMessageReceived(String msg);
  }
}